<?php
define('POST_AGREE'		, 'AGREE');
define('POST_OPPOSITE'	, 'OPPOSITE');
class Cl_PostReact extends WdkClass 
{
	protected
		/******************************************************/
		//	원본 테이블 정보
		/******************************************************/
		$post_react_seq			= 0				,	//
		$fk_post_seq			= 0				,	//	
		$fk_user_seq			= 0				,	//	
		$post_react_site		= POST_AGREE	,	//	
		$post_react_insert_time	= 0				,	//	
		$post_react_insert_ip	= ''			;	//	
		/******************************************************/
		//	추가 정보
		/******************************************************/
	
	/**
	 * 	
	 */
	function __construct()
	{
		parent::__construct();
		self::getDbo();
	}
	
	/**
	 *	
	 */
	public function __init($data)
	{
		parent::__init($data);
		self::dformat();
	}
	
	/**
	 *	
	 */
	public function load($post_react_seq)
	{
		/*------------------------------------------------------------*/
		$dbo = self::getDbo();
		/*------------------------------------------------------------*/
		self::__init($dbo->cLoad($post_react_seq));
	}
	
	/**
	 *	
	 */
	public function loadByPost($post_seq=0, $user_seq=0)
	{
		/*------------------------------------------------------------*/
		$dbo = self::getDbo();
		/*------------------------------------------------------------*/
		self::__init($dbo->cLoadByPost($post_seq, $user_seq));
	}
	
	/**
	 *	
	 */
	public function dformat()
	{
	}
	
	/**
	 *	
	 */
	public function insert($log="")
	{
		/*------------------------------------------------------------*/
		$dbo = self::getDbo();
		/*------------------------------------------------------------*/

		$this->post_react_insert_time	= time();
		
		$data = array(	'fk_post_seq'				=>	$this->fk_post_seq,
						'fk_user_seq'				=>	$this->fk_user_seq,
						'post_react_site'			=>	$this->post_react_site,
						'post_react_insert_time'	=>	$this->post_react_insert_time,
						'post_react_insert_ip'		=>	isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1'
					);
		$this->post_react_seq = $dbo->insert($data);
		/******************************************************/
		parent::setBackupData(array_keys($data));
		$this->backup($log);
		/******************************************************/
	}
	
	/**
	 * 
	 */
	public function update()
	{
		throw new DatabaseDisableException("");		
	}
	
	/**
	 * 
	 */
	public function delete()
	{
		throw new DatabaseDisableException("");
	}
	
	/**
	 * 
	 */
	public function agree($post_seq=0, $user_seq=0)
	{
		if($user_seq == 0) return;
		$this->fk_post_seq		=	$post_seq;
		$this->fk_user_seq		=	$user_seq;
		$this->post_react_site	=	POST_AGREE;
		$this->insert("Agree");
	}
	
	/**
	 * 
	 */
	public function opposite($post_seq=0, $user_seq=0)
	{
		if($user_seq == 0) return;
		$this->fk_post_seq		=	$post_seq;
		$this->fk_user_seq		=	$user_seq;
		$this->post_react_site	=	POST_OPPOSITE;
		$this->insert("Opposite");
	}
	
	/**
	 *	
	 */
	private function backup($log='')
	{
		/*------------------------------------------------------------*/
		$dbo = self::getDbo();
		/*------------------------------------------------------------*/
		$dbo->log($this->post_react_seq, $log, $this->backup_data);
	}
	
	/**
	 * 
	 */
	public function getDbo()
	{
		return Wdk::model(substr(__CLASS__, 3));
	}
}